home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / EXAMPLES / IDRAW / COMMANDS.C next >
C/C++ Source or Header  |  1992-01-29  |  26KB  |  840 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: commands.c,v 1.18 90/01/24 17:57:39 interran Exp $
  24. // implements class Commands.
  25.  
  26. #include "commands.h"
  27. #include "editor.h"
  28. #include "ipaint.h"
  29. #include "istring.h"
  30. #include "keystrokes.h"
  31. #include "mapipaint.h"
  32. #include "mapkey.h"
  33. #include "sllines.h"
  34. #include "state.h"
  35. #include <InterViews/box.h>
  36. #include <InterViews/painter.h>
  37. #include <InterViews/sensor.h>
  38. #include <InterViews/shape.h>
  39.  
  40. // An IdrawCommand enters itself into the MapKey so KeyEvent&s may be
  41. // mapped to IdrawCommands.
  42.  
  43. class IdrawCommand : public PullDownMenuCommand {
  44. public:
  45.     IdrawCommand(PullDownMenuActivator*, const char*, char, Editor*,
  46.          MapKey* = nil);
  47. protected:
  48.     Editor* editor;             // handles drawing and editing operations
  49. };
  50.  
  51. // IdrawCommand passes a printable string representing the given
  52. // character for its key string and enters itself into the character's
  53. // slot in the MapKey.
  54.  
  55. IdrawCommand::IdrawCommand (PullDownMenuActivator* a, const char* n, char c,
  56. Editor* e, MapKey* mk) : (a, n, mk ? mk->ToStr(c) : "") {
  57.     editor = e;
  58.     if (mk != nil) {
  59.     mk->Enter(this, c);
  60.     }
  61. }
  62.  
  63. // Each class below encapsulates a label, character, and command.
  64.  
  65. class NewCommand : public IdrawCommand {
  66. public:
  67.     NewCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  68.     : (a, "New", NEWCHAR, e, mk) {}
  69.     void Execute (Event&) {
  70.     editor->New();
  71.     }
  72. };
  73.  
  74. class RevertCommand : public IdrawCommand {
  75. public:
  76.     RevertCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  77.     : (a, "Revert", REVERTCHAR, e, mk) {}
  78.     void Execute (Event&) {
  79.     editor->Revert();
  80.     }
  81. };
  82.  
  83. class OpenCommand : public IdrawCommand {
  84. public:
  85.     OpenCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  86.     : (a, "Open...", OPENCHAR, e, mk) {}
  87.     void Execute (Event&) {
  88.     editor->Open();
  89.     }
  90. };
  91.  
  92. class SaveCommand : public IdrawCommand {
  93. public:
  94.     SaveCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  95.     : (a, "Save", SAVECHAR, e, mk) {}
  96.     void Execute (Event&) {
  97.     editor->Save();
  98.     }
  99. };
  100.  
  101. class SaveAsCommand : public IdrawCommand {
  102. public:
  103.     SaveAsCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  104.     : (a, "Save As...", SAVEASCHAR, e, mk) {}
  105.     void Execute (Event&) {
  106.     editor->SaveAs();
  107.     }
  108. };
  109.  
  110. class PrintCommand : public IdrawCommand {
  111. public:
  112.     PrintCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  113.     : (a, "Print...", PRINTCHAR, e, mk) {}
  114.     void Execute (Event&) {
  115.     editor->Print();
  116.     }
  117. };
  118.  
  119. class QuitCommand : public IdrawCommand {
  120. public:
  121.     QuitCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  122.     : (a, "Quit", QUITCHAR, e, mk) {}
  123.     void Execute (Event& e) {
  124.     editor->Quit(e);
  125.     }
  126. };
  127.  
  128. class UndoCommand : public IdrawCommand {
  129. public:
  130.     UndoCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  131.     : (a, "Undo", UNDOCHAR, e, mk) {}
  132.     void Execute (Event&) {
  133.     editor->Undo();
  134.     }
  135. };
  136.  
  137. class RedoCommand : public IdrawCommand {
  138. public:
  139.     RedoCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  140.     : (a, "Redo", REDOCHAR, e, mk) {}
  141.     void Execute (Event&) {
  142.     editor->Redo();
  143.     }
  144. };
  145.  
  146. class CutCommand : public IdrawCommand {
  147. public:
  148.     CutCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  149.     : (a, "Cut", CUTCHAR, e, mk) {}
  150.     void Execute (Event&) {
  151.     editor->Cut();
  152.     }
  153. };
  154.  
  155. class CopyCommand : public IdrawCommand {
  156. public:
  157.     CopyCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  158.     : (a, "Copy", COPYCHAR, e, mk) {}
  159.     void Execute (Event&) {
  160.     editor->Copy();
  161.     }
  162. };
  163.  
  164. class PasteCommand : public IdrawCommand {
  165. public:
  166.     PasteCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  167.     : (a, "Paste", PASTECHAR, e, mk) {}
  168.     void Execute (Event&) {
  169.     editor->Paste();
  170.     }
  171. };
  172.  
  173. class DuplicateCommand : public IdrawCommand {
  174. public:
  175.     DuplicateCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  176.     : (a, "Duplicate", DUPLICATECHAR, e, mk) {}
  177.     void Execute (Event&) {
  178.     editor->Duplicate();
  179.     }
  180. };
  181.  
  182. class DeleteCommand : public IdrawCommand {
  183. public:
  184.     DeleteCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  185.     : (a, "Delete", DELETECHAR, e, mk) {}
  186.     void Execute (Event&) {
  187.     editor->Delete();
  188.     }
  189. };
  190.  
  191. class SelectAllCommand : public IdrawCommand {
  192. public:
  193.     SelectAllCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  194.     : (a, "Select All", SELECTALLCHAR, e, mk) {}
  195.     void Execute (Event&) {
  196.     editor->SelectAll();
  197.     }
  198. };
  199.  
  200. class FlipHorizontalCommand : public IdrawCommand {
  201. public:
  202.     FlipHorizontalCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  203.     : (a, "Flip Horizontal", FLIPHORIZONTALCHAR, e, mk) {}
  204.     void Execute (Event&) {
  205.     editor->FlipHorizontal();
  206.     }
  207. };
  208.  
  209. class FlipVerticalCommand : public IdrawCommand {
  210. public:
  211.     FlipVerticalCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  212.     : (a, "Flip Vertical", FLIPVERTICALCHAR, e, mk) {}
  213.     void Execute (Event&) {
  214.     editor->FlipVertical();
  215.     }
  216. };
  217.  
  218. class _90ClockwiseCommand : public IdrawCommand {
  219. public:
  220.     _90ClockwiseCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  221.     : (a, "90 Clockwise", _90CLOCKWISECHAR, e, mk) {}
  222.     void Execute (Event&) {
  223.     editor->_90Clockwise();
  224.     }
  225. };
  226.  
  227. class _90CounterCWCommand : public IdrawCommand {
  228. public:
  229.     _90CounterCWCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  230.     : (a, "90 CounterCW", _90COUNTERCWCHAR, e, mk) {}
  231.     void Execute (Event&) {
  232.     editor->_90CounterCW();
  233.     }
  234. };
  235.  
  236. class PreciseMoveCommand : public IdrawCommand {
  237. public:
  238.     PreciseMoveCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  239.     : (a, "Precise Move...", PRECISEMOVECHAR, e, mk) {}
  240.     void Execute (Event&) {
  241.     editor->PreciseMove();
  242.     }
  243. };
  244.  
  245. class PreciseScaleCommand : public IdrawCommand {
  246. public:
  247.     PreciseScaleCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  248.     : (a, "Precise Scale...", PRECISESCALECHAR, e, mk) {}
  249.     void Execute (Event&) {
  250.     editor->PreciseScale();
  251.     }
  252. };
  253.  
  254. class PreciseRotateCommand : public IdrawCommand {
  255. public:
  256.     PreciseRotateCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  257.     : (a, "Precise Rotate...", PRECISEROTATECHAR, e, mk) {}
  258.     void Execute (Event&) {
  259.     editor->PreciseRotate();
  260.     }
  261. };
  262.  
  263. class GroupCommand : public IdrawCommand {
  264. public:
  265.     GroupCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  266.     : (a, "Group", GROUPCHAR, e, mk) {}
  267.     void Execute (Event&) {
  268.     editor->Group();
  269.     }
  270. };
  271.  
  272. class UngroupCommand : public IdrawCommand {
  273. public:
  274.     UngroupCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  275.     : (a, "Ungroup", UNGROUPCHAR, e, mk) {}
  276.     void Execute (Event&) {
  277.     editor->Ungroup();
  278.     }
  279. };
  280.  
  281. class BringToFrontCommand : public IdrawCommand {
  282. public:
  283.     BringToFrontCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  284.     : (a, "Bring To Front", BRINGTOFRONTCHAR, e, mk) {}
  285.     void Execute (Event&) {
  286.     editor->BringToFront();
  287.     }
  288. };
  289.  
  290. class SendToBackCommand : public IdrawCommand {
  291. public:
  292.     SendToBackCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  293.     : (a, "Send To Back", SENDTOBACKCHAR, e, mk) {}
  294.     void Execute (Event&) {
  295.     editor->SendToBack();
  296.     }
  297. };
  298.  
  299. class NumberOfGraphicsCommand : public IdrawCommand {
  300. public:
  301.     NumberOfGraphicsCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  302.     : (a, "Number of Graphics", NUMBEROFGRAPHICSCHAR, e, mk) {}
  303.     void Execute (Event&) {
  304.     editor->NumberOfGraphics();
  305.     }
  306. };
  307.  
  308. class FontCommand : public IdrawCommand {
  309. public:
  310.     FontCommand (PullDownMenuActivator* a, Editor* e, IFont* f)
  311.     : (a, f->GetPrintFontAndSize(), '\0', e) {
  312.     font = f;
  313.     }
  314.     void Execute (Event&) {
  315.     editor->SetFont(font);
  316.     }
  317. protected:
  318.     void Reconfig () {
  319.     Font* f = *font;
  320.     if (output->GetFont() != f) {
  321.         Painter* copy = new Painter(output);
  322.         copy->Reference();
  323.         Unref(output);
  324.         output = copy;
  325.         output->SetFont(f);
  326.     }
  327.     IdrawCommand::Reconfig();
  328.     }
  329.     void Resize () {            // need constant left pad to line up entries
  330.     const int xpad = 6;
  331.     name_x = xpad;
  332.     name_y = (ymax - output->GetFont()->Height() + 1) / 2;
  333.     key_x = key_y = 0;
  334.     }
  335.     IFont* font;                // stores font to give Editor
  336. };
  337.  
  338. static const int PICXMAX = 47;  // chosen to minimize scaling for canvas
  339. static const int PICYMAX = 14;
  340.  
  341. class BrushCommand : public IdrawCommand {
  342. public:
  343.     BrushCommand (PullDownMenuActivator* a, Editor* e, IBrush* b)
  344.     : (a, "None", '\0', e) {
  345.     brush = b;
  346.     brindic = new LineSelection(0, 0, PICXMAX, 0);
  347.     brindic->SetBrush(brush);
  348.     brindic->SetColors(pblack, pwhite);
  349.     brindic->FillBg(true);
  350.     brindic->SetPattern(psolid);
  351.     }
  352.     ~BrushCommand () {
  353.     delete brindic;
  354.     }
  355.     void Execute (Event&) {
  356.     editor->SetBrush(brush);
  357.     }
  358.     void Highlight (boolean on) {
  359.     if (highlighted != on) {
  360.         brindic->SetColors(brindic->GetBgColor(), brindic->GetFgColor());
  361.     }
  362.     IdrawCommand::Highlight(on);
  363.     }
  364. protected:
  365.     void Reconfig () {
  366.     IdrawCommand::Reconfig();
  367.     PColor* fg = brindic->GetFgColor();
  368.     PColor* bg = brindic->GetBgColor();
  369.     if (*fg != output->GetFgColor() || *bg != output->GetBgColor()) {
  370.         fg = new IColor(output->GetFgColor(), "");
  371.         bg = new IColor(output->GetBgColor(), "");
  372.         brindic->SetColors(fg, bg);
  373.     }
  374.     }
  375.     void Redraw (Coord l, Coord b, Coord r, Coord t) {
  376.     if (brush->None()) {
  377.         IdrawCommand::Redraw(l, b, r, t);
  378.     } else {
  379.         output->ClearRect(canvas, l, b, r, t);
  380.         brindic->Draw(canvas);
  381.     }
  382.     }
  383.     void Resize () {
  384.     IdrawCommand::Resize();
  385.     float xmag = float(xmax - 2*name_x) / PICXMAX;
  386.     float hy = float(ymax) / 2;
  387.     brindic->SetTransformer(nil);
  388.     brindic->Scale(xmag, 1.);
  389.     brindic->Translate(float(name_x), hy);
  390.     }
  391.     IBrush* brush;              // stores brush to give Editor
  392.     Graphic* brindic;           // displays line to demonstrate brush's effect
  393. };
  394.  
  395. class PatternCommand : public IdrawCommand {
  396. public:
  397.     PatternCommand (PullDownMenuActivator* a, Editor* e, IPattern* p)
  398.     : (a, "None", '\0', e) {
  399.     pattern = p;
  400.     patindic = nil;
  401.     }
  402.     ~PatternCommand () {
  403.     Unref(patindic);
  404.     }
  405.     void Execute (Event&) {
  406.     editor->SetPattern(pattern);
  407.     }
  408. protected:
  409.     void Reconfig () {
  410.     IdrawCommand::Reconfig();
  411.     if (patindic == nil) {
  412.         patindic = new Painter;
  413.         patindic->Reference();
  414.         patindic->SetPattern(*pattern);
  415.     }
  416.     }
  417.     void Redraw (Coord l, Coord b, Coord r, Coord t) {
  418.     if (pattern->None()) {
  419.         IdrawCommand::Redraw(l, b, r, t);
  420.     } else {
  421.         output->ClearRect(canvas, l, b, r, t);
  422.         patindic->FillRect(canvas, name_x,name_y,xmax-name_x,ymax-name_y);
  423.         output->Rect(canvas, name_x, name_y, xmax-name_x, ymax-name_y);
  424.     }
  425.     }
  426.     IPattern* pattern;          // stores pattern to give Editor
  427.     Painter* patindic;          // fills rect to demonstrate pat's effect
  428. };
  429.  
  430. class ColorCommand : public IdrawCommand {
  431. public:
  432.     ColorCommand (PullDownMenuActivator* a, Editor* e, IColor* c)
  433.     : (a, c->GetName(), '\0', e) {
  434.     key = "   ";
  435.     color = c;
  436.     colorindic = nil;
  437.     }
  438.     ~ColorCommand () {
  439.     key = nil;
  440.     Unref(colorindic);
  441.     }
  442. protected:
  443.     void Reconfig () {
  444.     IdrawCommand::Reconfig();
  445.     if (colorindic == nil) {
  446.         colorindic = new Painter(output);
  447.         colorindic->Reference();
  448.         colorindic->SetColors(*color, colorindic->GetBgColor());
  449.     }
  450.     }
  451.     void Redraw (Coord l, Coord b, Coord r, Coord t) {
  452.     IdrawCommand::Redraw(l, b, r, t);
  453.     colorindic->FillRect(canvas, key_x, key_y, xmax-name_x, ymax-name_y);
  454.     output->Rect(canvas, key_x, key_y, xmax-name_x, ymax-name_y);
  455.     }
  456.     IColor* color;              // stores color to give Editor
  457.     Painter* colorindic;        // fills rect to demonstrate color's effect
  458. };
  459.  
  460. class FgColorCommand : public ColorCommand {
  461. public:
  462.     FgColorCommand (PullDownMenuActivator* a, Editor* e, IColor* c)
  463.     : (a, e, c) {}
  464.     void Execute (Event&) {
  465.     editor->SetFgColor(color);
  466.     }
  467. };
  468.  
  469. class BgColorCommand : public ColorCommand {
  470. public:
  471.     BgColorCommand (PullDownMenuActivator* a, Editor* e, IColor* c)
  472.     : (a, e, c) {}
  473.     void Execute (Event&) {
  474.     editor->SetBgColor(color);
  475.     }
  476. };
  477.  
  478. class AlignLeftSidesCommand : public IdrawCommand {
  479. public:
  480.     AlignLeftSidesCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  481.     : (a, "Left Sides", ALIGNLEFTSIDESCHAR, e, mk) {}
  482.     void Execute (Event&) {
  483.     editor->AlignLeftSides();
  484.     }
  485. };
  486.  
  487. class AlignRightSidesCommand : public IdrawCommand {
  488. public:
  489.     AlignRightSidesCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  490.     : (a, "Right Sides", ALIGNRIGHTSIDESCHAR, e, mk) {}
  491.     void Execute (Event&) {
  492.     editor->AlignRightSides();
  493.     }
  494. };
  495.  
  496. class AlignBottomsCommand : public IdrawCommand {
  497. public:
  498.     AlignBottomsCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  499.     : (a, "Bottoms", ALIGNBOTTOMSCHAR, e, mk) {}
  500.     void Execute (Event&) {
  501.     editor->AlignBottoms();
  502.     }
  503. };
  504.  
  505. class AlignTopsCommand : public IdrawCommand {
  506. public:
  507.     AlignTopsCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  508.     : (a, "Tops", ALIGNTOPSCHAR, e, mk) {}
  509.     void Execute (Event&) {
  510.     editor->AlignTops();
  511.     }
  512. };
  513.  
  514. class AlignVertCentersCommand : public IdrawCommand {
  515. public:
  516.     AlignVertCentersCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  517.     : (a, "Vert Centers", ALIGNVERTCENTERSCHAR, e, mk) {}
  518.     void Execute (Event&) {
  519.     editor->AlignVertCenters();
  520.     }
  521. };
  522.  
  523. class AlignHorizCentersCommand : public IdrawCommand {
  524. public:
  525.     AlignHorizCentersCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  526.     : (a, "Horiz Centers", ALIGNHORIZCENTERSCHAR, e, mk) {}
  527.     void Execute (Event&) {
  528.     editor->AlignHorizCenters();
  529.     }
  530. };
  531.  
  532. class AlignCentersCommand : public IdrawCommand {
  533. public:
  534.     AlignCentersCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  535.     : (a, "Centers", ALIGNCENTERSCHAR, e, mk) {}
  536.     void Execute (Event&) {
  537.     editor->AlignCenters();
  538.     }
  539. };
  540.  
  541. class AlignLeftToRightCommand : public IdrawCommand {
  542. public:
  543.     AlignLeftToRightCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  544.     : (a, "Left To Right", ALIGNLEFTTORIGHTCHAR, e, mk) {}
  545.     void Execute (Event&) {
  546.     editor->AlignLeftToRight();
  547.     }
  548. };
  549.  
  550. class AlignRightToLeftCommand : public IdrawCommand {
  551. public:
  552.     AlignRightToLeftCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  553.     : (a, "Right To Left", ALIGNRIGHTTOLEFTCHAR, e, mk) {}
  554.     void Execute (Event&) {
  555.     editor->AlignRightToLeft();
  556.     }
  557. };
  558.  
  559. class AlignBottomToTopCommand : public IdrawCommand {
  560. public:
  561.     AlignBottomToTopCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  562.     : (a, "Bottom To Top", ALIGNBOTTOMTOTOPCHAR, e, mk) {}
  563.     void Execute (Event&) {
  564.     editor->AlignBottomToTop();
  565.     }
  566. };
  567.  
  568. class AlignTopToBottomCommand : public IdrawCommand {
  569. public:
  570.     AlignTopToBottomCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  571.     : (a, "Top To Bottom", ALIGNTOPTOBOTTOMCHAR, e, mk) {}
  572.     void Execute (Event&) {
  573.     editor->AlignTopToBottom();
  574.     }
  575. };
  576.  
  577. class AlignToGridCommand : public IdrawCommand {
  578. public:
  579.     AlignToGridCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  580.     : (a, "Align To Grid", ALIGNTOGRIDCHAR, e, mk) {}
  581.     void Execute (Event&) {
  582.     editor->AlignToGrid();
  583.     }
  584. };
  585.  
  586. class ReduceCommand : public IdrawCommand {
  587. public:
  588.     ReduceCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  589.     : (a, "Reduce", REDUCECHAR, e, mk) {}
  590.     void Execute (Event&) {
  591.     editor->Reduce();
  592.     }
  593. };
  594.  
  595. class EnlargeCommand : public IdrawCommand {
  596. public:
  597.     EnlargeCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  598.     : (a, "Enlarge", ENLARGECHAR, e, mk) {}
  599.     void Execute (Event&) {
  600.     editor->Enlarge();
  601.     }
  602. };
  603.  
  604. class NormalSizeCommand : public IdrawCommand {
  605. public:
  606.     NormalSizeCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  607.     : (a, "Normal Size", NORMALSIZECHAR, e, mk) {}
  608.     void Execute (Event&) {
  609.     editor->NormalSize();
  610.     }
  611. };
  612.  
  613. class ReduceToFitCommand : public IdrawCommand {
  614. public:
  615.     ReduceToFitCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  616.     : (a, "Reduce To Fit", REDUCETOFITCHAR, e, mk) {}
  617.     void Execute (Event&) {
  618.     editor->ReduceToFit();
  619.     }
  620. };
  621.  
  622. class CenterPageCommand : public IdrawCommand {
  623. public:
  624.     CenterPageCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  625.     : (a, "Center Page", CENTERPAGECHAR, e, mk) {}
  626.     void Execute (Event&) {
  627.     editor->CenterPage();
  628.     }
  629. };
  630.  
  631. class RedrawPageCommand : public IdrawCommand {
  632. public:
  633.     RedrawPageCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  634.     : (a, "Redraw Page", REDRAWPAGECHAR, e, mk) {}
  635.     void Execute (Event&) {
  636.     editor->RedrawPage();
  637.     }
  638. };
  639.  
  640. class GriddingOnOffCommand : public IdrawCommand {
  641. public:
  642.     GriddingOnOffCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  643.     : (a, "Gridding on/off", GRIDDINGONOFFCHAR, e, mk) {}
  644.     void Execute (Event&) {
  645.     editor->GriddingOnOff();
  646.     }
  647. };
  648.  
  649. class GridVisibleInvisibleCommand : public IdrawCommand {
  650. public:
  651.     GridVisibleInvisibleCommand (PullDownMenuActivator* a,Editor* e,MapKey* mk)
  652.     : (a, "Grid visible/invisible", GRIDVISIBLEINVISIBLECHAR, e, mk) {}
  653.     void Execute (Event&) {
  654.     editor->GridVisibleInvisible();
  655.     }
  656. };
  657.  
  658. class GridSpacingCommand : public IdrawCommand {
  659. public:
  660.     GridSpacingCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  661.     : (a, "Grid spacing...", GRIDSPACINGCHAR, e, mk) {}
  662.     void Execute (Event&) {
  663.     editor->GridSpacing();
  664.     }
  665. };
  666.  
  667. class OrientationCommand : public IdrawCommand {
  668. public:
  669.     OrientationCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  670.     : (a, "Orientation", ORIENTATIONCHAR, e, mk) {}
  671.     void Execute (Event&) {
  672.     editor->Orientation();
  673.     }
  674. };
  675.  
  676. class ShowVersionCommand : public IdrawCommand {
  677. public:
  678.     ShowVersionCommand (PullDownMenuActivator* a, Editor* e, MapKey* mk)
  679.     : IdrawCommand (a, "", SHOWVERSIONCHAR, e, mk) {
  680.     Listen(noEvents);
  681.     };
  682.     void Execute (Event&) {
  683.     editor->ShowVersion();
  684.     }
  685. protected:
  686.     void Reconfig () {
  687.     shape->width = shape->height = 0;
  688.     }
  689. };
  690.  
  691. // Commands creates its commands.
  692.  
  693. Commands::Commands (Editor* e, MapKey* mk, State* s) {
  694.     Init(e, mk, s);
  695. }
  696.  
  697. // Init creates the activators and commands, inserts the commands into
  698. // menus, gives the menus to the activators, and inserts the activators.
  699.  
  700. void Commands::Init (Editor* e, MapKey* mk, State* state) {
  701.     PullDownMenuActivator* file = new PullDownMenuActivator(this, "File");
  702.     PullDownMenuActivator* edit = new PullDownMenuActivator(this, "Edit");
  703.     PullDownMenuActivator* strc = new PullDownMenuActivator(this, "Structure");
  704.     PullDownMenuActivator* font = new PullDownMenuActivator(this, "Font");
  705.     PullDownMenuActivator* brush = new PullDownMenuActivator(this, "Brush");
  706.     PullDownMenuActivator* pat = new PullDownMenuActivator(this, "Pattern");
  707.     PullDownMenuActivator* fgcolor = new PullDownMenuActivator(this,"FgColor");
  708.     PullDownMenuActivator* bgcolor = new PullDownMenuActivator(this,"BgColor");
  709.     PullDownMenuActivator* align = new PullDownMenuActivator(this, "Align");
  710.     PullDownMenuActivator* option = new PullDownMenuActivator(this, "Option");
  711.  
  712.     Scene* filemenu = new VBox;
  713.     filemenu->Insert(new NewCommand(file, e, mk));
  714.     filemenu->Insert(new RevertCommand(file, e, mk));
  715.     filemenu->Insert(new PullDownMenuDivider);
  716.     filemenu->Insert(new OpenCommand(file, e, mk));
  717.     filemenu->Insert(new SaveCommand(file, e, mk));
  718.     filemenu->Insert(new SaveAsCommand(file, e, mk));
  719.     filemenu->Insert(new PrintCommand(file, e, mk));
  720.     filemenu->Insert(new PullDownMenuDivider);
  721.     filemenu->Insert(new QuitCommand(file, e, mk));
  722.  
  723.     Scene* editmenu = new VBox;
  724.     editmenu->Insert(new UndoCommand(edit, e, mk));
  725.     editmenu->Insert(new RedoCommand(edit, e, mk));
  726.     editmenu->Insert(new CutCommand(edit, e, mk));
  727.     editmenu->Insert(new CopyCommand(edit, e, mk));
  728.     editmenu->Insert(new PasteCommand(edit, e, mk));
  729.     editmenu->Insert(new DuplicateCommand(edit, e, mk));
  730.     editmenu->Insert(new DeleteCommand(edit, e, mk));
  731.     editmenu->Insert(new SelectAllCommand(edit, e, mk));
  732.     editmenu->Insert(new PullDownMenuDivider);
  733.     editmenu->Insert(new FlipHorizontalCommand(edit, e, mk));
  734.     editmenu->Insert(new FlipVerticalCommand(edit, e, mk));
  735.     editmenu->Insert(new _90ClockwiseCommand(edit, e, mk));
  736.     editmenu->Insert(new _90CounterCWCommand(edit, e, mk));
  737.     editmenu->Insert(new PullDownMenuDivider);
  738.     editmenu->Insert(new PreciseMoveCommand(edit, e, mk));
  739.     editmenu->Insert(new PreciseScaleCommand(edit, e, mk));
  740.     editmenu->Insert(new PreciseRotateCommand(edit, e, mk));
  741.  
  742.     Scene* structuremenu = new VBox;
  743.     structuremenu->Insert(new GroupCommand(strc, e, mk));
  744.     structuremenu->Insert(new UngroupCommand(strc, e, mk));
  745.     structuremenu->Insert(new BringToFrontCommand(strc, e, mk));
  746.     structuremenu->Insert(new SendToBackCommand(strc, e, mk));
  747.     structuremenu->Insert(new PullDownMenuDivider);
  748.     structuremenu->Insert(new NumberOfGraphicsCommand(strc, e, mk));
  749.  
  750.     Scene* fontmenu = new VBox;
  751.     MapIFont* mf = state->GetMapIFont();
  752.     for (IFont* f = mf->First(); !mf->AtEnd(); f = mf->Next()) {
  753.     fontmenu->Insert(new FontCommand(font, e, f));
  754.     }
  755.  
  756.     Scene* brushmenu = new VBox;
  757.     MapIBrush* mb = state->GetMapIBrush();
  758.     for (IBrush* b = mb->First(); !mb->AtEnd(); b = mb->Next()) {
  759.     brushmenu->Insert(new BrushCommand(brush, e, b));
  760.     }
  761.  
  762.     Scene* patternmenu = new VBox;
  763.     MapIPattern* mp = state->GetMapIPattern();
  764.     for (IPattern* p = mp->First(); !mp->AtEnd(); p = mp->Next()) {
  765.     patternmenu->Insert(new PatternCommand(pat, e, p));
  766.     }
  767.  
  768.     Scene* fgcolormenu = new VBox;
  769.     MapIColor* mfg = state->GetMapIFgColor();
  770.     for (IColor* fg = mfg->First(); !mfg->AtEnd(); fg = mfg->Next()) {
  771.     fgcolormenu->Insert(new FgColorCommand(fgcolor, e, fg));
  772.     }
  773.  
  774.     Scene* bgcolormenu = new VBox;
  775.     MapIColor* mbg = state->GetMapIBgColor();
  776.     for (IColor* bg = mbg->First(); !mbg->AtEnd(); bg = mbg->Next()) {
  777.     bgcolormenu->Insert(new BgColorCommand(bgcolor, e, bg));
  778.     }
  779.  
  780.     Scene* alignmenu = new VBox;
  781.     alignmenu->Insert(new AlignLeftSidesCommand(align, e, mk));
  782.     alignmenu->Insert(new AlignRightSidesCommand(align, e, mk));
  783.     alignmenu->Insert(new AlignBottomsCommand(align, e, mk));
  784.     alignmenu->Insert(new AlignTopsCommand(align, e, mk));
  785.     alignmenu->Insert(new AlignVertCentersCommand(align, e, mk));
  786.     alignmenu->Insert(new AlignHorizCentersCommand(align, e, mk));
  787.     alignmenu->Insert(new AlignCentersCommand(align, e, mk));
  788.     alignmenu->Insert(new AlignLeftToRightCommand(align, e, mk));
  789.     alignmenu->Insert(new AlignRightToLeftCommand(align, e, mk));
  790.     alignmenu->Insert(new AlignBottomToTopCommand(align, e, mk));
  791.     alignmenu->Insert(new AlignTopToBottomCommand(align, e, mk));
  792.     alignmenu->Insert(new AlignToGridCommand(align, e, mk));
  793.  
  794.     Scene* optionmenu = new VBox;
  795.     optionmenu->Insert(new ReduceCommand(option, e, mk));
  796.     optionmenu->Insert(new EnlargeCommand(option, e, mk));
  797.     optionmenu->Insert(new NormalSizeCommand(option, e, mk));
  798.     optionmenu->Insert(new ReduceToFitCommand(option, e, mk));
  799.     optionmenu->Insert(new CenterPageCommand(option, e, mk));
  800.     optionmenu->Insert(new RedrawPageCommand(option, e, mk));
  801.     optionmenu->Insert(new PullDownMenuDivider);
  802.     optionmenu->Insert(new GriddingOnOffCommand(option, e, mk));
  803.     optionmenu->Insert(new GridVisibleInvisibleCommand(option, e, mk));
  804.     optionmenu->Insert(new GridSpacingCommand(option, e, mk));
  805.     optionmenu->Insert(new OrientationCommand(option, e, mk));
  806.     optionmenu->Insert(new ShowVersionCommand(option, e, mk));
  807.  
  808.     file->SetMenu(filemenu);
  809.     edit->SetMenu(editmenu);
  810.     strc->SetMenu(structuremenu);
  811.     font->SetMenu(fontmenu);
  812.     brush->SetMenu(brushmenu);
  813.     pat->SetMenu(patternmenu);
  814.     fgcolor->SetMenu(fgcolormenu);
  815.     bgcolor->SetMenu(bgcolormenu);
  816.     align->SetMenu(alignmenu);
  817.     option->SetMenu(optionmenu);
  818.  
  819.     Scene* activators = new HBox;
  820.     activators->Insert(file);
  821.     activators->Insert(edit);
  822.     activators->Insert(strc);
  823.     activators->Insert(font);
  824.     activators->Insert(brush);
  825.     activators->Insert(pat);
  826.     activators->Insert(fgcolor);
  827.     activators->Insert(bgcolor);
  828.     activators->Insert(align);
  829.     activators->Insert(option);
  830.  
  831.     Insert(activators);
  832. }
  833.  
  834. // Reconfig makes Commands' shape unstretchable but shrinkable.
  835.  
  836. void Commands::Reconfig () {
  837.     PullDownMenuBar::Reconfig();
  838.     shape->Rigid(hfil, 0, 0, 0);
  839. }
  840.